package com.huopaolan.yohuoshop.Mvp.View.Fragment;

import android.graphics.Color;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;

import com.huopaolan.lib_core.Base.BaseFragment;
import com.huopaolan.yohuoshop.Adapter.StrollCommunityAdapter;
import com.huopaolan.yohuoshop.Bean.StrollCommunityEntity;
import com.huopaolan.yohuoshop.Di.Compont.DaggerStrollCommunityFragmentCompont;
import com.huopaolan.yohuoshop.Di.Modules.StrollCommunityFragmentModules;
import com.huopaolan.yohuoshop.Mvp.Contract.CommunityFragmentContract;
import com.huopaolan.yohuoshop.Mvp.Presenter.StrollCommunityPresenter;
import com.huopaolan.yohuoshop.R;
import com.jwenfeng.library.pulltorefresh.BaseRefreshListener;
import com.jwenfeng.library.pulltorefresh.PullToRefreshLayout;

public class StrollCommunityFragment extends BaseFragment<StrollCommunityPresenter> implements CommunityFragmentContract.CommunityWriteIView, BaseRefreshListener {
    private PullToRefreshLayout pullToRefreshLayout;
    private RecyclerView recyclerView;
    private StrollCommunityAdapter strollCommunityAdapter;

    @Override
    public View createView(LayoutInflater inflater) {
        return inflater.inflate(R.layout.fragment_strollcommunity, null);
    }

    @Override
    public void onStart() {
        Window window = getActivity().getWindow();
        window.setStatusBarColor(Color.BLACK);
        super.onStart();
    }

    @Override
    public void initView(View view) {
        //初始化
        pullToRefreshLayout = view.findViewById(R.id.stroll_community_pull);
        pullToRefreshLayout.setRefreshListener(this);
        recyclerView = view.findViewById(R.id.stroll_community_recycler);
        //配置适配器
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);
        strollCommunityAdapter = new StrollCommunityAdapter(R.layout.item_stroll_community_layout);
        recyclerView.setAdapter(strollCommunityAdapter);
    }

    @Override
    public void initData() {
        p.CommunityDataRequest();
    }

    @Override
    public void setUpDagger() {
        DaggerStrollCommunityFragmentCompont.builder()
                .strollCommunityFragmentModules(new StrollCommunityFragmentModules(this))
                .build().inject(this);
    }

    @Override
    public void CommunityWriteSuccess(StrollCommunityEntity entity) {
        if (entity.values == null) {
            return;
        }
        strollCommunityAdapter.addData(entity.values);
    }

    @Override
    public void showDialog() {

    }

    @Override
    public void hideDialog() {

    }

    @Override
    public void refresh() {
        strollCommunityAdapter.getData().clear();
        p.CommunityDataRequest();
        pullToRefreshLayout.finishRefresh();
    }

    @Override
    public void loadMore() {
        pullToRefreshLayout.finishLoadMore();
    }
}
